import service from '@/utils/axios';
import { FileRO, FileVO } from '@/api/file/file';
import { IResponseType } from '@/api/common';

export const upload = (data: FileRO) => {
    const formData = new FormData();
    formData.append('fileType', data.fileType.toString());
    data.multipartFiles.forEach((file) => {
        formData.append('multipartFiles', file);
    });
    formData.append('uploadType', data.uploadType.toString());
    if (data.uploadPermissions)
        formData.append('uploadPermissions', data.uploadPermissions.toString());
    if (data.expirationDate) formData.append('expirationDate', data.expirationDate.toString());
    return service<IResponseType<FileVO>>({
        url: '/file/upload',
        method: 'post',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data: formData
    });
};
